<?php
!defined('QAPP') AND exit('Forbidden');
if (!defined('AppDir')) {
    exit("未正确调用或安装");
}
_stripslashes();

!empty($_SERVER['HTTP_X_REWRITE_URL']) AND $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
!isset($_SERVER['REQUEST_URI']) AND $_SERVER['REQUEST_URI'] = '';
!isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] = '';
!isset($_SERVER['SERVER_ADDR']) AND $_SERVER['SERVER_ADDR'] = '';


if (!file_exists(AppDir . 'apphash.php')) {
    exit("未正确安装");
}
require(AppDir . 'apphash.php');

$cacheConfig['memcached']['cachepre'] = SiteHash . '_';
$cacheConfig['redis']['cachepre'] = SiteHash . '_';
setGlobals('cache', cache_new($cacheConfig));

define('cookiehash', substr(md5(SiteHash), 0, 6));
$site_db = array();
if ($dbConfig['type'] == "sqlite" || $dbConfig['type'] == "sqlitepdo") {
    $dbfile = $dbConfig['sqlite']['file'];
    if ($dbfile == "auto") {
        $dbfile = DBDir . DBHash . '.db';
    }
    $site_db = array('database' => 'sqlitepdo', 'dbfile' => $dbfile, 'tableex' => TableEx);
} else if ($dbConfig['type'] == "mysql" || $dbConfig['type'] == "mysqlpdo") {
    $site_db = array('database' => 'mysqlpdo', 'host' => $dbConfig['mysql']['host'], 'port' => $dbConfig['mysql']['port'], 'dbname' => $dbConfig['mysql']['dbname'], 'user' => $dbConfig['mysql']['user'], 'password' => $dbConfig['mysql']['password'], 'tableex' => TableEx);
}

//dump_pre($site_db);
//修复站点在子目录下的bug
$uri = $_SERVER["REQUEST_URI"];
if (SystemDir != "/") {
    $systemDir = SystemDir;
    if (substr(SystemDir, 0, 1) != '/') {
        $systemDir = '/' . $systemDir;
    }
    $uri = substr($uri, strlen($systemDir));
    if (substr($uri, 0, 1) != '/') {
        $uri = '/' . $uri;
    }
}

//修复目录访问时多一个斜杠
if (substr($uri, -1) == '/') {
    $uri = substr($uri, 0, strlen($uri) - 1);
}

$_SERVER["REQUEST_URI"] = $uri;